/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import entities.Domain;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import entities.*;
import java.*;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author xuanthuy
 */
@Stateless
public class DomainFacade extends AbstractFacade<Domain> {

    @PersistenceContext(unitName = "AlluringDecorsPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DomainFacade() {
        super(Domain.class);
    }

    // select all
    public List<Domain> truyvanAll() {
        try {
            Query q = this.em.createQuery("select dm FROM Domain dm where dm.status=TRUE");
            return q.getResultList();
        } catch (Exception e) {
            return null;
        }
    }
    
    // xoa an
    public List<Domain> truyvan1() {
        try {
            Query q = this.em.createQuery("select dm FROM Domain dm where dm.status=FALSE");
            return q.getResultList();
        } catch (Exception e) {
            return null;
        }
    }
    
    // kiem tra su ton tai
    public Domain checkExists(String name){
        try {
            Query q = this.em.createQuery("SELECT dm from Domain dm where dm.name=:name");
            q.setParameter("name", name);
            return (Domain) q.getSingleResult();
        } catch (Exception e) {
            return null;
        }
    }
}
